﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace TimKiemDichVu
{
    public partial class ChooseDistrictPage : PhoneApplicationPage
    {
        public ChooseDistrictPage()
        {
            InitializeComponent();
        }

        private void CheckAll(bool bValue)
        {
            ckbAll.IsChecked = bValue;
            ckbBinhTanDistrict.IsChecked = bValue;
            ckbBinhThanhDistrict.IsChecked = bValue;
            ckbDistrict1.IsChecked = bValue;
            ckbDistrict10.IsChecked = bValue;
            ckbDistrict11.IsChecked = bValue;
            ckbDistrict12.IsChecked = bValue;
            ckbDistrict2.IsChecked = bValue;
            ckbDistrict3.IsChecked = bValue;
            ckbDistrict4.IsChecked = bValue;
            ckbDistrict5.IsChecked = bValue;
            ckbDistrict6.IsChecked = bValue;
            ckbDistrict7.IsChecked = bValue;
            ckbDistrict8.IsChecked = bValue;
            ckbDistrict9.IsChecked = bValue;
            ckbGoVapDistrict.IsChecked = bValue;
            ckbHocMonDistrict.IsChecked = bValue;
            ckbNhaBeDistrict.IsChecked = bValue;
            ckbPhuNhuanDistrict.IsChecked = bValue;
            ckbTanBinhDistrict.IsChecked = bValue;
            ckbTanPhuDistrict.IsChecked = bValue;
            ckbThuDucDistrict.IsChecked = bValue;            
        }

        private List<int> GetDistrictList()
        {
            List<int> districtList = new List<int>();

            #region
            if (ckbDistrict1.IsChecked.Value)
                districtList.Add(1);

            if (ckbTanBinhDistrict.IsChecked.Value)
                districtList.Add(2);

            if (ckbDistrict4.IsChecked.Value)
                districtList.Add(3);

            if (ckbDistrict5.IsChecked.Value)
                districtList.Add(4);

            if (ckbDistrict6.IsChecked.Value)
                districtList.Add(5);

            if (ckbDistrict8.IsChecked.Value)
                districtList.Add(6);

            if (ckbDistrict9.IsChecked.Value)
                districtList.Add(7);

            if (ckbDistrict10.IsChecked.Value)
                districtList.Add(8);

            if (ckbTanPhuDistrict.IsChecked.Value)
                districtList.Add(9);

            if (ckbBinhTanDistrict.IsChecked.Value)
                districtList.Add(10);

            if (ckbBinhThanhDistrict.IsChecked.Value)
                districtList.Add(11);

            if (ckbDistrict3.IsChecked.Value)
                districtList.Add(12);

            if (ckbDistrict7.IsChecked.Value)
                districtList.Add(13);

            if (ckbDistrict2.IsChecked.Value)
                districtList.Add(14);

            if (ckbDistrict11.IsChecked.Value)
                districtList.Add(15);

            if (ckbDistrict12.IsChecked.Value)
                districtList.Add(16);

            if (ckbPhuNhuanDistrict.IsChecked.Value)
                districtList.Add(17);

            if (ckbGoVapDistrict.IsChecked.Value)
                districtList.Add(18);

            if (ckbNhaBeDistrict.IsChecked.Value)
                districtList.Add(19);

            if (ckbThuDucDistrict.IsChecked.Value)
                districtList.Add(20);

            if (ckbHocMonDistrict.IsChecked.Value)
                districtList.Add(21);            
            #endregion

            if (districtList.Count == (Application.Current as App).define.nDistrictName)
            {
                districtList.Clear();
                districtList.Add(0);
            }

            return districtList;
        }

        private void ckbAll_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.			
        }

        private void ckbAll_Click(object sender, RoutedEventArgs e)
        {
            if (ckbAll.IsChecked.Value)
            {
                CheckAll(true);
            }
            else
            {
                CheckAll(false);
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            (Application.Current as App).type = 1;
            if (GetDistrictList().Count > 0)
            {
                (Application.Current as App).district.IndexList.Clear();
                (Application.Current as App).district.IndexList = GetDistrictList();                
            }            
            NavigationService.GoBack();
        }
    }
}
